#include "NetDebug.h"
#include <spdlog/sinks/stdout_sinks.h>
#include "spdlog/sinks/rotating_file_sink.h"

namespace LiteNetLib::NetDebug
{
    bool logOutput = false;
    NetDebugLevel logLevel = NetDebugLevel::LOG_INFO;

    std::shared_ptr<spdlog::logger> consoleLog = nullptr;
    std::shared_ptr<spdlog::logger> debugLog = nullptr;

    void Init()
    {
        logOutput = true;

        // 创建一个多线程控制台日志器
        consoleLog = spdlog::stdout_logger_mt("LiteNetLib_console_logger");
        consoleLog->set_pattern("[%H:%M:%S.%e][%n][%l] %v");

        // 每 5MB 生成一个新的日志文件
        debugLog = spdlog::rotating_logger_mt("LiteNetLib", "Logs/LiteNetLibCpp.log", 1024 * 1024 * 5, 3);
        debugLog->set_pattern("[%Y-%m-%d %H:%M:%S.%e][%l] %v");
        debugLog->sinks().push_back(consoleLog->sinks().front());
    }

    void Dispose()
    {
        if (debugLog != nullptr)
        {
            debugLog->flush();
            debugLog = nullptr;
        }
        consoleLog = nullptr;
    }
}

